﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="NotificationManager.aspx.cs" Inherits="GPSTrackingWebsiteManager.Pages.NotificationsManager" %>

<!DOCTYPE html>

<link href="../../Css/GPSTrackingWebsite.css" rel="stylesheet" />
<link href="../../Css/messi.css" rel="stylesheet" />
<script src="../../Javascript/jquery-1.11.1.min.js"></script>
<script src="../../Javascript/messi.js"></script>
<script src="../../Javascript/Custom.js"></script>
<script src="../../Javascript/WindowMessageManager.js"></script>
<script src="../../Javascript/ObjectsV2.js"></script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
        <script type="text/javascript">

            //Windows Message Manager 
            var objWindowsMessageManager = new WindowsMessageManager();
            objWindowsMessageManager.run();


            var opener = GetRadWindow();
            var NotificationManager = new NotificationManager();
            var RoutesManager = new RoutesManager();
            var Companies = new Companies();
            var GeoFences = new GeoFences();

            function clearObjects() {
                if (opener.globalNotificationManager.geoFenceIDSelected != -1) {
                    index = GeoFences.getIndexGeoFenceID(opener.globalNotificationManager.geoFencesList, opener.globalNotificationManager.geoFenceIDSelected);

                    if (index != -1) {
                        opener.globalNotificationManager.geoFencesList[index].hideGeoFence(opener);
                    }
                }
            }

            function restorePage() {
                if (opener.globalNotificationManager.geoFenceIDSelected != -1) {
                    index = GeoFences.getIndexGeoFenceID(opener.globalNotificationManager.geoFencesList, opener.globalNotificationManager.geoFenceIDSelected);

                    if (index != -1) {
                        opener.globalNotificationManager.geoFencesList[index].showGeoFence(opener);
                    }
                }
            }

            function GetRadWindow() {
                var oWindow = null;
                if (window.radWindow)
                    oWindow = window.radWindow;
                else if (window.frameElement.radWindow)
                    oWindow = window.frameElement.radWindow;
                return oWindow.BrowserWindow;
            }

            /*function CompaniesGrid_OnRowClick(sender, args) {
                NotificationManager.clearAllPolygonoGeoFenceList(opener);
                if (GeoFences.isValidToGetGeoFences(getGeoFenceGrid(), opener.globalNotificationManager.companyIDSelected, args.getDataKeyValue("CompanyID"), opener.globalNotificationManager.geoFencesList, opener.globalNotificationManager.companiesList, opener.globalNotificationManager.geoFencesDataSource)) {
                    opener.globalNotificationManager.companyIDSelected = args.getDataKeyValue("CompanyID");
                    opener.globalNotificationManager.geoFenceIDSelected = -1;
                    opener.globalNotificationManager.gpsGroupIDSelected = -1;
                    clearList(opener.globalNotificationManager.gpsStockList);
                    clearDataSource(opener.globalNotificationManager.gpsStockDataSource, getGPSStockGrid(), true);
                    getckbNotyToAdmin().checked = false;
                    getckbNotyToUser().checked = false;
                    getGeoFencesByCompanyID();
                    getAllGPSGroupsByCompanyIDAndAdminUsername();
                }
            }*/

            function getInfo() {
                getCompaniesByAdminUsername();
                getNotifications();
                isActive = true;
            }

            function getCompaniesByAdminUsername() {
                requestStart(getrpvNotificationManagerUpdateControl());
                PageMethods.wsGetCompaniesByAdminUsername(getCompaniesByAdminUsernameOk, getCompaniesByAdminUsernameError);
            }

            function getCompaniesByAdminUsernameOk(object) {
                Companies.openXMLCompaniesByAdminUsername(object, opener.globalNotificationManager.companiesList);
                Companies.loadCompaniesDataSource(getCompaniesGrid(), opener.globalNotificationManager.companiesList, opener.globalNotificationManager.companiesDataSource);
                if (opener.globalNotificationManager.companiesList.length == 1) {
                    getCompaniesGrid().selectItem(0);
                    responseEnd(getrpvNotificationManagerUpdateControl());
                    CompaniesGridSelected(opener.globalNotificationManager.companiesList[0].companyID);
                }
                else {
                    responseEnd(getrpvNotificationManagerUpdateControl());
                }
            }

            function getCompaniesByAdminUsernameError(error) {
                responseEnd(getrpvNotificationManagerUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.notifications, opener.globalNotificationManager.widthForMsg);
                
            }

            function CompaniesGrid_OnRowClick(sender, args) {
                CompaniesGridSelected(args.getDataKeyValue("CompanyID"));
            }

            function CompaniesGridSelected(companyID) {
                var index = Companies.getIndexCompanyID(companyID);
                if (index != -1) {
                    opener.globalNotificationManager.companyIDSelected = companyID;
                    getDepartmentsByCompanyID();


                    NotificationManager.clearAllPolygonoGeoFenceList(opener);
                    if (GeoFences.isValidToGetGeoFences(getGeoFenceGrid(), opener.globalNotificationManager.companyIDSelected, companyID, opener.globalNotificationManager.geoFencesList, opener.globalNotificationManager.companiesList, opener.globalNotificationManager.geoFencesDataSource)) {

                        opener.globalNotificationManager.departmentIDSelected = -1;
                        opener.globalNotificationManager.geoFenceIDSelected = -1;
                        opener.globalNotificationManager.gpsGroupIDSelected = -1;
                        //clearList(opener.globalNotificationManager.gpsStockList);
                        clearDataSource(opener.globalNotificationManager.gpsStockDataSource, getGPSStockGrid(), true);
                        //getckbNotyToAdmin().checked = false;
                        //getckbNotyToUser().checked = false;
                        getGeoFencesByCompanyID();
                    }
                    

                }
            }

            function getDepartmentsByCompanyID() {
                requestStart(getrpvNotificationManagerUpdateControl());
                PageMethods.wsGetAllDepartmentsByCompanyIDAndAdminUsername(opener.globalNotificationManager.companyIDSelected, getDepartmentsByCompanyIDOk, getDepartmentsByCompanyIDError);
            }

            function getDepartmentsByCompanyIDOk(object) {

                clearList(opener.globalNotificationManager.usersGroupsList);
                clearDataSource(opener.globalNotificationManager.usersGroupsDataSource, getUsersGroupsGrid(), true);

                clearList(opener.globalNotificationManager.usersList);
                clearDataSource(opener.globalNotificationManager.usersDataSource, getUsersRoutesGrid(), true);

                clearList(opener.globalNotificationManager.gpsImeiList);
                clearDataSource(opener.globalNotificationManager.gpsImeiDataSource, getGpsRoutesGrid(), true);

                RoutesManager.openXMLDepartmentsByCompanyID(object, opener.globalNotificationManager.departmentsList);
                RoutesManager.loadDepartmentsDataSource(getDeparmentsGrid(), opener.globalNotificationManager.departmentsDataSource, opener.globalNotificationManager.departmentsList);

                if (opener.globalNotificationManager.departmentsList.length == 1) {
                    getDeparmentsGrid().selectItem(0);
                    responseEnd(getrpvNotificationManagerUpdateControl());
                    DepartmentsGridSelected(opener.globalNotificationManager.departmentsList[0].departmentID);
                }
                else {
                    responseEnd(getrpvNotificationManagerUpdateControl());
                }
            }

            function getDepartmentsByCompanyIDError(error) {
                responseEnd(getrpvNotificationManagerUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.notifications);
            }

            function DepartmentsGrid_OnRowClick(sender, args) {
                DepartmentsGridSelected(args.getDataKeyValue("DepartmentID"));
            }

            function DepartmentsGridSelected(departmentID) {
                var index = RoutesManager.getIndexDepartmentID(opener.globalNotificationManager.departmentsList, departmentID);
                if (index != -1) {
                    opener.globalNotificationManager.departmentIDSelected = departmentID;
                    getUsersGroupsByDepartmentID();
                }
            }

            function getUsersGroupsByDepartmentID() {
                requestStart(getrpvNotificationManagerUpdateControl());
                PageMethods.wsGetAllUsersGroupsByDepartmentID(opener.globalNotificationManager.departmentIDSelected, getUsersGroupsByDepartmentIDOk, getUsersGroupsByDepartmentIDError);
            }

            function getUsersGroupsByDepartmentIDOk(object) {

                clearList(opener.globalNotificationManager.usersList);
                clearDataSource(opener.globalNotificationManager.usersDataSource, getUsersRoutesGrid(), true);

                clearList(opener.globalNotificationManager.gpsImeiList);
                clearDataSource(opener.globalNotificationManager.gpsImeiDataSource, getGpsRoutesGrid(), true);

                RoutesManager.openXMLUsersGroupsByDepartmentID(object, opener.globalNotificationManager.usersGroupsList);
                RoutesManager.loadUsersGroupsDataSource(getUsersGroupsGrid(), opener.globalNotificationManager.usersGroupsDataSource, opener.globalNotificationManager.usersGroupsList);

                if (opener.globalNotificationManager.usersGroupsList.length == 1) {
                    getUsersGroupsGrid().selectItem(0);
                    responseEnd(getrpvNotificationManagerUpdateControl());
                    UsersGroupsGridSelected(opener.globalNotificationManager.usersGroupsList[0].userGroupID);
                }
                else {
                    responseEnd(getrpvNotificationManagerUpdateControl());
                }
            }

            function getUsersGroupsByDepartmentIDError(error) {
                responseEnd(getrpvNotificationManagerUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.notifications);
            }

            function UsersGroupsGrid_OnRowClick(sender, args) {
                UsersGroupsGridSelected(args.getDataKeyValue("UserGroupID"));
            }

            function UsersGroupsGridSelected(userGroupID) {
                var index = RoutesManager.getIndexUserGroupID(opener.globalNotificationManager.usersGroupsList, userGroupID);
                if (index != -1) {
                    opener.globalNotificationManager.userGroupIDSelected = userGroupID;
                    getAllUsersByUserGroupID();
                }
            }

            function getAllUsersByUserGroupID() {
                requestStart(getrpvNotificationManagerUpdateControl());
                PageMethods.wsGetUsersByUserGroupID(opener.globalNotificationManager.userGroupIDSelected, getAllUsersByUserGroupIDOk, getAllUsersByUserGroupIDError);
            }

            function getAllUsersByUserGroupIDOk(object) {
                clearList(opener.globalNotificationManager.usersList);
                clearDataSource(opener.globalNotificationManager.usersDataSource, getUsersRoutesGrid(), true);

                clearList(opener.globalNotificationManager.gpsImeiList);
                clearDataSource(opener.globalNotificationManager.gpsImeiDataSource, getGpsRoutesGrid(), true);

                RoutesManager.openXMLUsersByUserGroupID(object, opener.globalNotificationManager.usersList);
                RoutesManager.loadUsersRouteByUserGroupIDDataSource(getUsersRoutesGrid(), opener.globalNotificationManager.usersDataSource, opener.globalNotificationManager.usersList);

                if (opener.globalNotificationManager.usersList.length == 1) {
                    getUsersRoutesGrid().selectItem(0);
                    //opener.globalNotificationManager.companyIDSelected = opener.globalNotificationManager.companiesList[0].companyID;
                    responseEnd(getrpvNotificationManagerUpdateControl());
                    UsersRouteGridSelected(opener.globalNotificationManager.usersList[0].username);
                }
                else {
                    responseEnd(getrpvNotificationManagerUpdateControl());
                }
                //responseEnd(getrpvNotificationManagerUpdateControl());
            }

            function getAllUsersByUserGroupIDError(error) {
                responseEnd(getrpvNotificationManagerUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.routesAdministrator);
            }

            function UsersRoutesGrid_OnRowClick(sender, args) {

                UsersRouteGridSelected(args.getDataKeyValue("Username"));
            }

            function UsersRouteGridSelected(username) {


                //if (opener.globalNotificationManager.usernameSelected != username) {
                opener.globalNotificationManager.usernameSelected = username;
                getAllGPSGroupsByCompanyIDAndAdminUsername();

                //getImeiByUser();
                //}
            }

            /*function getImeiByUser() {
                requestStart(getrpvNotificationManagerUpdateControl());
                PageMethods.wsGetImeiByUser(opener.globalNotificationManager.companyIDSelected, opener.globalNotificationManager.usernameSelected, getImeiByUserOk, getImeiByUserError);
            }

            function getImeiByUserOk(object) {
                clearList(opener.globalNotificationManager.gpsImeiList);
                clearDataSource(opener.globalNotificationManager.gpsImeiDataSource, getGpsRoutesGrid(), true);

                RoutesManager.openXMLImeiByUser(object, opener.globalNotificationManager.gpsImeiList);
                RoutesManager.loadImeiDataSource(getGpsRoutesGrid(), opener.globalNotificationManager.gpsImeiDataSource, opener.globalNotificationManager.gpsImeiList);

                responseEnd(getrpvNotificationManagerUpdateControl());
            }

            function getImeiByUserError(error) {
                responseEnd(getrpvNotificationManagerUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.routesAdministrator);
            }*/

            

            function getGeoFencesByCompanyID() {
                requestStart(getrpvNotificationManagerUpdateControl());
                clearList(opener.globalNotificationManager.gpsGroupList);
                clearDataSource(opener.globalNotificationManager.gpsGroupDataSource, getGPSGroupGrid(), true);
                PageMethods.wsGetGeoFencesByCompanyID(opener.globalNotificationManager.companyIDSelected, getGeoFencesByCompanyIDOk, getGeoFencesByCompanyIDError);
            }

            function getGeoFencesByCompanyIDOk(object) {

                GeoFences.openXMLGeoFenceDetails(opener, object, opener.globalNotificationManager.geoFencesList);
                GeoFences.loadGeoFenceDataSource(opener.globalNotificationManager.geoFencesDataSource, opener.globalNotificationManager.geoFencesList, getGeoFenceGrid());
                responseEnd(getrpvNotificationManagerUpdateControl());
            }

            function getGeoFencesByCompanyIDError(error) {
                responseEnd(getrpvNotificationManagerUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.notifications, opener.globalNotificationManager.widthForMsg);
            }

            /*function getAllGPSGroupsByCompanyIDAndAdminUsername() {
                PageMethods.wsGetAllGPSGroupsByCompanyIDAndAdminUsername(opener.globalNotificationManager.companyIDSelected, getAllGPSGroupsByCompanyIDAndAdminUsernameOk, getAllGPSGroupsByCompanyIDAndAdminUsernameError);
            }
    
            function getAllGPSGroupsByCompanyIDAndAdminUsernameOk(object) {
                NotificationManager.openXMLGPSGroups(object, opener.globalNotificationManager.gpsGroupList);
                NotificationManager.loadGPSGroupDataSource(getGPSGroupGrid(), opener.globalNotificationManager.gpsGroupList, opener.globalNotificationManager.gpsGroupDataSource);
            }
    
            function getAllGPSGroupsByCompanyIDAndAdminUsernameError(error) {
                responseEnd(getrpvNotificationManagerUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.notifications, opener.globalNotificationManager.widthForMsg);
            }*/

            

            function getNotifications() {
                PageMethods.wsGetAllNotifications_TypeGeoFences(getNotificationsOk, getNotificationsError);
            }

            function getNotificationsOk(object) {
                NotificationManager.openXMLNotifications(object, opener.globalNotificationManager.notificationsList);
                NotificationManager.loadNotificationDataSource(getNotificationGrid(), opener.globalNotificationManager.notificationsList, opener.globalNotificationManager.notificationsDataSource);
            }

            function getNotificationsError(error) {
                responseEnd(getrpvNotificationManagerUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.notifications, opener.globalNotificationManager.widthForMsg);
            }

            function GPSStockGrid_OnRowSelection(sender, args) {
                var index = -1;

                index = NotificationManager.getIndexGPSImei(opener.globalNotificationManager.gpsStockList, args.getDataKeyValue("GPSImei"));

                if (index != -1) {
                    opener.globalNotificationManager.gpsStockList[index].currentAction = "I";
                    opener.globalNotificationManager.gpsImeiSelected = args.getDataKeyValue("GPSImei");
                }
            }

            function GPSStockGrid_OnRowDeselecting(sender, args) {
                var index = -1;

                index = NotificationManager.getIndexGPSImei(opener.globalNotificationManager.gpsStockList, args.getDataKeyValue("GPSImei"));

                if (index != -1) {
                    opener.globalNotificationManager.gpsStockList[index].currentAction = "D";
                    opener.globalNotificationManager.gpsImeiSelected = args.getDataKeyValue("GPSImei");
                }
            }

            function NotificationsGrid_OnRowClick(sender, args) {
                var index = -1;

                index = NotificationManager.getIndexNotificationID(opener.globalNotificationManager.notificationsList, args.getDataKeyValue("NotificationID"));

                if (index != -1) {
                    opener.globalNotificationManager.notificationIDSelected = args.getDataKeyValue("NotificationID");
                    if (opener.globalNotificationManager.geoFenceIDSelected != -1 && opener.globalNotificationManager.gpsGroupIDSelected != -1) {
                        getAllGPSStockByGPSGroupIDAndNotificationIDAndGeoFenceID();
                    }
                }
            }

            //Show Geofence on row selecting
            function GeoFenceGrid_OnRowClick(sender, args) {

                var index = -1;

                index = GeoFences.getIndexGeoFenceID(opener.globalNotificationManager.geoFencesList, opener.globalNotificationManager.geoFenceIDSelected);
                if (index != -1) {
                    opener.globalNotificationManager.geoFencesList[index].checked = false;
                    opener.globalNotificationManager.geoFencesList[index].hideGeoFence(opener);
                }

                index = GeoFences.getIndexGeoFenceID(opener.globalNotificationManager.geoFencesList, args.getDataKeyValue("GeoFenceID"));

                if (index != -1) {
                    opener.globalNotificationManager.geoFencesList[index].checked = true;
                    opener.objMapControl.centerMap(opener.objMapControl.addPosition(opener.globalNotificationManager.geoFencesList[index].latitudeList[0], opener.globalNotificationManager.geoFencesList[index].longitudeList[0]));
                    opener.objMapControl.zoomMap(10);
                    opener.globalNotificationManager.geoFencesList[index].showGeoFence(opener);
                    opener.globalNotificationManager.geoFenceIDSelected = args.getDataKeyValue("GeoFenceID");
                    if (opener.globalNotificationManager.notificationIDSelected != -1 && opener.globalNotificationManager.gpsGroupIDSelected != -1) {
                        getAllGPSStockByGPSGroupIDAndNotificationIDAndGeoFenceID();
                    }
                }
            }

            function getAllGPSStockByGPSGroupIDAndNotificationIDAndGeoFenceID() {
                requestStart(getrpvNotificationManagerUpdateControl());
                PageMethods.wsGetAllGPSStockByGPSGroupIDAndNotificationIDAndGeoFenceID(opener.globalNotificationManager.gpsGroupIDSelected, opener.globalNotificationManager.notificationIDSelected, opener.globalNotificationManager.geoFenceIDSelected, opener.globalNotificationManager.usernameSelected, opener.globalNotificationManager.companyIDSelected, getAllGPSStockByGPSGroupIDAndNotificationIDAndGeoFenceIDOk, getAllGPSStockByGPSGroupIDAndNotificationIDAndGeoFenceIDError);
            }

            function getAllGPSStockByGPSGroupIDAndNotificationIDAndGeoFenceIDOk(object) {
                clearList(opener.globalNotificationManager.gpsStockList);
                clearDataSource(opener.globalNotificationManager.gpsStockDataSource, getGPSStockGrid(), true);
                NotificationManager.openXMLGPSStock(object, opener.globalNotificationManager.gpsStockList, opener);
                NotificationManager.loadGPSStockDataSource(getGPSStockGrid(), opener.globalNotificationManager.gpsStockList, opener.globalNotificationManager.gpsStockDataSource);
                //getckbNotyToAdmin().checked = opener.globalNotificationManager.lastNotyGeoFenceToSendAdmin;
                //getckbNotyToUser().checked = opener.globalNotificationManager.lastNotyGPSImeiToSendUser;
                responseEnd(getrpvNotificationManagerUpdateControl());
            }

            function getAllGPSStockByGPSGroupIDAndNotificationIDAndGeoFenceIDError(error) {
                responseEnd(getrpvNotificationManagerUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.notifications, opener.globalNotificationManager.widthForMsg);
            }

            function getAllGPSGroupsByCompanyIDAndAdminUsername() {
                requestStart(getrpvNotificationManagerUpdateControl());
                PageMethods.wsGetAllGPSGroupsByCompanyIDAndAdminUsername(opener.globalNotificationManager.companyIDSelected, getAllGPSGroupsByCompanyIDAndAdminUsernameOk, getAllGPSGroupsByCompanyIDAndAdminUsernameError)
            }

            function getAllGPSGroupsByCompanyIDAndAdminUsernameOk(object) {
                NotificationManager.openXMLGPSGroups(object, opener.globalNotificationManager.gpsGroupList);
                NotificationManager.loadGPSGroupDataSource(getGPSGroupGrid(), opener.globalNotificationManager.gpsGroupList, opener.globalNotificationManager.gpsGroupDataSource);
                responseEnd(getrpvNotificationManagerUpdateControl());
            }

            function getAllGPSGroupsByCompanyIDAndAdminUsernameError(error) {
                responseEnd(getrpvNotificationManagerUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.notifications, opener.globalNotificationManager.widthForMsg);
            }

            function clearGeoFenceSelected() {
                var index = GeoFences.getIndexGeoFenceID(opener.globalNotificationManager.geoFencesList, opener.globalNotificationManager.geoFenceIDSelected);
                if (index != -1) {
                    opener.globalNotificationManager.geoFencesList[index].hideGeoFence(opener);
                    getGeoFenceGrid().clearSelectedItems();
                    opener.globalNotificationManager.geoFenceIDSelected = -1;
                    getAllGPSStockByGPSGroupIDAndNotificationIDAndGeoFenceID();
                }
            }

            function GPSGroupsGrid_OnRowClick(sender, args) {

                var index = -1;

                index = NotificationManager.getIndexGPSGroupID(opener.globalNotificationManager.gpsGroupList, args.getDataKeyValue("GPSGroupID"));

                if (index != -1) {
                    opener.globalNotificationManager.gpsGroupIDSelected = args.getDataKeyValue("GPSGroupID");
                    getAllGPSStockByGPSGroupIDAndNotificationIDAndGeoFenceID();
                }
            }

            function isValidToInsertNotifications() {
                if (NotificationManager.isValidToInsertNotifications(opener)) {
                    requestStart(getrpvNotificationManagerUpdateControl());
                    notificationsInsert_Delete_Update_TypeGeoFences();
                }
            }

            function notificationsInsert_Delete_Update_TypeGeoFences() {
                var gpsImeiListToInsert = [];
                var gpsImeiListToDelete = [];

                for (i = 0; i < opener.globalNotificationManager.gpsImeiListToInsert.length; i++) { gpsImeiListToInsert.push(opener.globalNotificationManager.gpsImeiListToInsert[i].toString()); }
                for (i = 0; i < opener.globalNotificationManager.gpsImeiListToDelete.length; i++) { gpsImeiListToDelete.push(opener.globalNotificationManager.gpsImeiListToDelete[i].toString()); }

                PageMethods.wsNotificationsInsert_Delete_Update_TypeGeoFences(opener.globalNotificationManager.geoFenceIDSelected, opener.globalNotificationManager.currentNotyGeoFenceToSendAdmin, opener.globalNotificationManager.isUpdateNotyGeoFenceToSendAdmin, opener.globalNotificationManager.currentNotyGPSImeiToSendUser, opener.globalNotificationManager.isUpdateNotyGPSImeiToSendUser, opener.globalNotificationManager.notificationIDSelected, gpsImeiListToInsert, gpsImeiListToDelete, opener.globalNotificationManager.usernameSelected, opener.globalNotificationManager.companyIDSelected, notificationsInsert_Delete_Update_TypeGeoFencesOk, notificationsInsert_Delete_Update_TypeGeoFencesError)
            }

            function notificationsInsert_Delete_Update_TypeGeoFencesOk(object) {
                opener.globalNotificationManager.lastNotyGeoFenceToSendAdmin = opener.globalNotificationManager.currentNotyGeoFenceToSendAdmin;
                opener.globalNotificationManager.lastNotyGPSImeiToSendUser = opener.globalNotificationManager.currentNotyGPSImeiToSendUser;
                for (i = 0; i < opener.globalNotificationManager.gpsStockList.length; i++) { opener.globalNotificationManager.gpsStockList[i].lastAction = opener.globalNotificationManager.gpsStockList[i].currentAction; }

                objWindowsMessageManager.show_Info("Se asociaron las notificaciones satisfactoriamente", titles.notifications, opener.globalNotificationManager.widthForMsg);
                responseEnd(getrpvNotificationManagerUpdateControl());
            }

            function notificationsInsert_Delete_Update_TypeGeoFencesError(error) {
                responseEnd(getrpvNotificationManagerUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.notifications, opener.globalNotificationManager.widthForMsg);
            }

            function CheckUncheckckbNotyToAdmin() {
                //opener.globalNotificationManager.currentNotyGeoFenceToSendAdmin = getckbNotyToAdmin().checked;
            }

            function CheckUncheckckbNotyToUser() {
                //opener.globalNotificationManager.currentNotyGPSImeiToSendUser = getckbNotyToUser().checked;
            }

            function getCompaniesGrid() {
                try {
                    return $find("<%= rgCompaniesGrid.ClientID %>").get_masterTableView();
                }
                catch (ex) {
                    setTimeout(getCompaniesGrid, 100);
                }
            }

            function getUsersGroupsGrid() {
                return $find("<%= rgUsersGroupsGrid.ClientID %>").get_masterTableView();
            }


            function getDeparmentsGrid() {
                return $find("<%= rgDepartmentsGrid.ClientID %>").get_masterTableView();
            }

            function getGpsRoutesGrid() {
                return $find("<%= rgGPSStockGrid.ClientID %>").get_masterTableView();
            }

            function getUsersRoutesGrid() {
                return $find("<%= rgUsersRoutesGrid.ClientID %>").get_masterTableView();
            }

            function getGPSGroupGrid() {
                try {
                    return $find("<%= rgGPSGroupsGrid.ClientID %>").get_masterTableView();
                }
                catch (ex) {
                    setTimeout(getCompaniesGrid, 100);
                }
            }

        function getGeoFenceGrid() {
            try {
                return $find("<%= rgGeoFenceGrid.ClientID %>").get_masterTableView();
            }
            catch (ex) {
                setTimeout(getGeoFenceGrid, 100);
            }
        }

        function getGPSStockGrid() {
            try {
                return $find("<%= rgGPSStockGrid.ClientID %>").get_masterTableView();
            }
            catch (ex) {
                setTimeout(getGPSStockGrid, 100);
            }
        }

        function getNotificationGrid() {
            try {
                return $find("<%= rgNotificationsGrid.ClientID %>").get_masterTableView();
            }
            catch (ex) {
                setTimeout(getNotificationGrid, 100);
            }
        }

        function getrpvNotificationManagerUpdateControl() {
            return "<%=  rpvNotificationManager.ClientID %>";
        }

        function getckbNotyToAdmin() {
            return $get('<%= ckbNotyToAdmin.ClientID %>');
        }

        function getckbNotyToUser() {
            return $get('<%= ckbNotyToUser.ClientID %>');
        }

        function requestStart(object) {
            try {
                $find("<%= RadAjaxLoadingPanel1.ClientID%>").show(object);
            }
            catch (e) {
                null;
            }
        }

        function responseEnd(object) {
            try {
                $find("<%= RadAjaxLoadingPanel1.ClientID%>").hide(object);
            }
            catch (e) {
                null;
            }
        }

        </script>
    </telerik:RadScriptBlock>
</head>
<body onload="getInfo()">
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true"></telerik:RadScriptManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="AjaxControlID1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="Loading" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>


        <telerik:RadTabStrip ID="rtsNotificationManager" runat="server" SelectedIndex="0" MultiPageID="rmpNotificationManager"></telerik:RadTabStrip>
        <telerik:RadMultiPage ID="rmpNotificationManager" runat="server" SelectedIndex="0">
            <telerik:RadPageView ID="rpvNotificationManager" runat="server">
                <table>
                    <tr>
                        <td colspan="3">
                            <table class="auto-style2">

                                <tr>
                                    <td>
                                        <fieldset>
                                            <legend>Compañias Registradas</legend>
                                            <telerik:RadGrid ID="rgCompaniesGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" OnNeedDataSource="rgCompaniesGrid_NeedDataSource" Width="300px">
                                                <ClientSettings>
                                                    <Selecting AllowRowSelect="True" />
                                                    <ClientEvents OnRowClick="CompaniesGrid_OnRowClick" />
                                                    <Scrolling AllowScroll="True" UseStaticHeaders="true" />
                                                </ClientSettings>
                                                <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="CompanyID" NoMasterRecordsText="No hay compañias registradas">
                                                    <CommandItemSettings ExportToPdfText="Export to PDF" />
                                                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                                    </RowIndicatorColumn>
                                                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                                    </ExpandCollapseColumn>
                                                    <Columns>
                                                        <telerik:GridBoundColumn DataField="CompanyID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="CompanyID" Display="false">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" Visible="true">
                                                        </telerik:GridBoundColumn>
                                                    </Columns>
                                                    <EditFormSettings>
                                                        <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                                        </EditColumn>
                                                    </EditFormSettings>
                                                </MasterTableView>
                                                <FilterMenu EnableImageSprites="true">
                                                </FilterMenu>
                                            </telerik:RadGrid>
                                        </fieldset>
                                    </td>

                                </tr>

                                <tr>
                                    <td>
                                        <fieldset>
                                            <legend>Departamentos</legend>
                                            <telerik:RadGrid ID="rgDepartmentsGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" Width="300px" OnNeedDataSource="rgDepartmentsGrid_NeedDataSource">
                                                <ClientSettings>
                                                    <Selecting AllowRowSelect="True" />
                                                    <ClientEvents OnRowClick="DepartmentsGrid_OnRowClick" />
                                                    <Scrolling AllowScroll="True" UseStaticHeaders="true" />
                                                </ClientSettings>
                                                <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="DepartmentID" NoMasterRecordsText="No hay Departamentos registrados">
                                                    <CommandItemSettings ExportToPdfText="Export to PDF" />
                                                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                                    </RowIndicatorColumn>
                                                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                                    </ExpandCollapseColumn>
                                                    <Columns>
                                                        <telerik:GridBoundColumn DataField="DepartmentID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="DepartmentID" Visible="false">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" Visible="true">
                                                        </telerik:GridBoundColumn>
                                                    </Columns>
                                                    <EditFormSettings>
                                                        <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                                        </EditColumn>
                                                    </EditFormSettings>
                                                </MasterTableView>
                                                <FilterMenu EnableImageSprites="true">
                                                </FilterMenu>
                                            </telerik:RadGrid>
                                        </fieldset>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <fieldset>
                                            <legend>Grupo de Usuarios</legend>
                                            <telerik:RadGrid ID="rgUsersGroupsGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" Width="300px" OnNeedDataSource="rgUsersGroupsGrid_NeedDataSource">
                                                <ClientSettings>
                                                    <Selecting AllowRowSelect="True" />
                                                    <ClientEvents OnRowClick="UsersGroupsGrid_OnRowClick" />
                                                    <Scrolling AllowScroll="True" UseStaticHeaders="true" />
                                                </ClientSettings>
                                                <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="UserGroupID" NoMasterRecordsText="No hay Grupos registrados">
                                                    <CommandItemSettings ExportToPdfText="Export to PDF" />
                                                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                                    </RowIndicatorColumn>
                                                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                                    </ExpandCollapseColumn>
                                                    <Columns>
                                                        <telerik:GridBoundColumn DataField="UserGroupID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="UserGroupID" Visible="false">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" Visible="true">
                                                        </telerik:GridBoundColumn>
                                                    </Columns>
                                                    <EditFormSettings>
                                                        <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                                        </EditColumn>
                                                    </EditFormSettings>
                                                </MasterTableView>
                                                <FilterMenu EnableImageSprites="true">
                                                </FilterMenu>
                                            </telerik:RadGrid>
                                        </fieldset>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <fieldset>
                                            <legend>Usuarios</legend>
                                            <telerik:RadGrid ID="rgUsersRoutesGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" Width="300px" OnNeedDataSource="rgUsersRoutesGrid_NeedDataSource">
                                                <ClientSettings>
                                                    <Selecting AllowRowSelect="True" />
                                                    <ClientEvents OnRowClick="UsersRoutesGrid_OnRowClick" />
                                                    <Scrolling AllowScroll="True" UseStaticHeaders="true" />
                                                </ClientSettings>
                                                <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="Username" NoMasterRecordsText="No hay usuarios registrados">
                                                    <CommandItemSettings ExportToPdfText="Export to PDF" />
                                                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                                    </RowIndicatorColumn>
                                                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                                    </ExpandCollapseColumn>
                                                    <Columns>
                                                        <telerik:GridBoundColumn DataField="Username" FilterControlAltText="Filter Description column" HeaderText="Username" UniqueName="Username" Display="false">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" HeaderStyle-Width="150px" ItemStyle-Width="150px">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn DataField="FirstName" FilterControlAltText="Filter Description column" HeaderText="Apellido1" HeaderStyle-Width="150px" ItemStyle-Width="150px">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn DataField="LastName" FilterControlAltText="Filter Description column" HeaderText="Apellido2" HeaderStyle-Width="150px" ItemStyle-Width="150px">
                                                        </telerik:GridBoundColumn>
                                                    </Columns>
                                                    <EditFormSettings>
                                                        <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                                        </EditColumn>
                                                    </EditFormSettings>
                                                </MasterTableView>
                                                <FilterMenu EnableImageSprites="true">
                                                </FilterMenu>
                                            </telerik:RadGrid>
                                        </fieldset>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <fieldset>
                                            <legend>Notificaciones Registradas</legend>
                                            <telerik:RadGrid ID="rgNotificationsGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" Width="300px" OnNeedDataSource="rgNotificationsGrid_NeedDataSource">
                                                <ClientSettings>
                                                    <Selecting AllowRowSelect="True" />
                                                    <ClientEvents OnRowClick="NotificationsGrid_OnRowClick" />
                                                    <Scrolling AllowScroll="True" UseStaticHeaders="true" />
                                                </ClientSettings>
                                                <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="NotificationID" NoMasterRecordsText="No hay notificaciones registradas">
                                                    <CommandItemSettings ExportToPdfText="Export to PDF" />
                                                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                                    </RowIndicatorColumn>
                                                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                                    </ExpandCollapseColumn>
                                                    <Columns>
                                                        <telerik:GridBoundColumn DataField="NotificationID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="NotificationID" Display="false">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" Visible="true">
                                                        </telerik:GridBoundColumn>
                                                    </Columns>
                                                    <EditFormSettings>
                                                        <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                                        </EditColumn>
                                                    </EditFormSettings>
                                                </MasterTableView>
                                                <FilterMenu EnableImageSprites="true">
                                                </FilterMenu>
                                            </telerik:RadGrid>
                                        </fieldset>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <fieldset>
                                            <legend>Geo Cercas Registradas</legend>
                                            <telerik:RadGrid ID="rgGeoFenceGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" Width="300px" OnNeedDataSource="rgGeoFenceGrid_NeedDataSource">
                                                <ClientSettings>
                                                    <Selecting AllowRowSelect="True" />
                                                    <ClientEvents OnRowClick="GeoFenceGrid_OnRowClick" />
                                                    <Scrolling AllowScroll="True" UseStaticHeaders="true" />
                                                </ClientSettings>
                                                <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="GeoFenceID" NoMasterRecordsText="No hay Geo Cercas registradas">
                                                    <CommandItemSettings ExportToPdfText="Export to PDF" />
                                                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                                    </RowIndicatorColumn>
                                                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                                    </ExpandCollapseColumn>
                                                    <Columns>
                                                        <telerik:GridBoundColumn DataField="GeoFenceID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="GeoFenceID" Display="false">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" Visible="true">
                                                        </telerik:GridBoundColumn>
                                                    </Columns>
                                                    <EditFormSettings>
                                                        <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                                        </EditColumn>
                                                    </EditFormSettings>
                                                </MasterTableView>
                                                <FilterMenu EnableImageSprites="true">
                                                </FilterMenu>
                                            </telerik:RadGrid>
                                        </fieldset>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <fieldset>
                                            <legend>Grupo de dispositivos registrados</legend>
                                            <telerik:RadGrid ID="rgGPSGroupsGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" Width="300px" OnNeedDataSource="rgGPSGroupsGrid_NeedDataSource">
                                                <ClientSettings>
                                                    <Selecting AllowRowSelect="True" />
                                                    <ClientEvents OnRowClick="GPSGroupsGrid_OnRowClick" />
                                                    <Scrolling AllowScroll="True" UseStaticHeaders="true" />
                                                </ClientSettings>
                                                <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="GPSGroupID" NoMasterRecordsText="No hay grupos de GPSImei registrados">
                                                    <CommandItemSettings ExportToPdfText="Export to PDF" />
                                                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                                    </RowIndicatorColumn>
                                                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                                    </ExpandCollapseColumn>
                                                    <Columns>
                                                        <telerik:GridBoundColumn DataField="GPSGroupID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="GPSGroupID" Visible="false">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" Visible="true">
                                                        </telerik:GridBoundColumn>
                                                    </Columns>
                                                    <EditFormSettings>
                                                        <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                                        </EditColumn>
                                                    </EditFormSettings>
                                                </MasterTableView>
                                                <FilterMenu EnableImageSprites="true">
                                                </FilterMenu>
                                            </telerik:RadGrid>
                                        </fieldset>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <fieldset>
                                            <legend>Dispositivos registrados</legend>
                                            <telerik:RadGrid ID="rgGPSStockGrid" runat="server" AllowMultiRowSelection="True" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" Width="300px" OnNeedDataSource="rgGPSStockGrid_NeedDataSource">
                                                <ClientSettings>
                                                    <Selecting AllowRowSelect="True" />
                                                    <ClientEvents OnRowDeselecting="GPSStockGrid_OnRowDeselecting" OnRowSelecting="GPSStockGrid_OnRowSelection" />
                                                    <Scrolling AllowScroll="True" UseStaticHeaders="true" />
                                                </ClientSettings>
                                                <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="GPSImei" NoMasterRecordsText="No hay GPSImei registrados">
                                                    <CommandItemSettings ExportToPdfText="Export to PDF" />
                                                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                                    </RowIndicatorColumn>
                                                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                                    </ExpandCollapseColumn>
                                                    <Columns>
                                                        <telerik:GridBoundColumn DataField="GPSImei" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="GPSImei" Display="false">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" Visible="true" ItemStyle-Width="240px" HeaderStyle-Width="240px">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridClientSelectColumn HeaderText="Mostrar" UniqueName="chkShowClient">
                                                        </telerik:GridClientSelectColumn>
                                                    </Columns>
                                                    <EditFormSettings>
                                                        <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                                        </EditColumn>
                                                    </EditFormSettings>
                                                </MasterTableView>
                                                <FilterMenu EnableImageSprites="true">
                                                </FilterMenu>

                                            </telerik:RadGrid>
                                        </fieldset>
                                    </td>
                                </tr>
                                
                                <tr>
                                    <td style="text-align: center">
                                        <asp:CheckBox ID="ckbNotyToAdmin" runat="server" onclick="javascript:CheckUncheckckbNotyToAdmin()" Text="Notificar Admin" Checked="false" Visible="false" />
                                        &nbsp&nbsp&nbsp&nbsp
                                    <asp:CheckBox ID="ckbNotyToUser" runat="server" onclick="javascript:CheckUncheckckbNotyToUser()" Text="Notificar Usuario" Checked="false" Visible="false" />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align: center">
                                        <input id="btnClearGeoFences" type="button" value="Limpiar GeoFence" onclick="clearGeoFenceSelected();" />
                                        &nbsp&nbsp&nbsp&nbsp
                                    <input id="btnUpdateGPSImei" type="button" value="Asociar GPSImei" onclick="isValidToInsertNotifications();" />
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </telerik:RadPageView>
        </telerik:RadMultiPage>

        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default"></telerik:RadAjaxLoadingPanel>
    </form>
</body>
</html>
